package cn.spcloud.user.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import cn.spcloud.core.entity.User;
import cn.spcloud.core.service.UserService;

@Controller
public class UserController {
	
	@Autowired
	UserService userService;
	
	@Autowired
	JmsTemplate jmsTemplate;
	
	@ResponseBody
	@GetMapping("/info")
	public String info(){
		return "oser info";
	}

	@ResponseBody
	@GetMapping("/list")
	public List<User> list(){
		return userService.userList();
	}
	
	@GetMapping("/login")
	public String login(HttpSession session){
		session.setAttribute("userName", "admin");
		return "usercenter";
	}
	
	
	
	@GetMapping("/reg")
	public String register(){
		
		//1.添加用户
		
		//发送注册用户成功通知
		//2.发送邮件
		//3.短信
		User user = new User();
		user.setId(1);
		user.setUserName("ADMIN");
		user.setEmail("123443@qq.com");
		user.setPhone("213456768");
		jmsTemplate.convertAndSend("user_reg",JSON.toJSONString(user));
		return "reg_success";
	}
}
